﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Web_ViewAnswer : System.Web.UI.Page
{
    protected List<Train> ts;
    protected Question question;

    protected void Page_Load(object sender, EventArgs e)
    {

        string qid = Request.Params["qid"];
        CmsDataContext db = new CmsDataContext();

        question = (from aQ in db.Question
                    where aQ.ID == qid
                    select aQ).First();

        if (!IsPostBack)
        {
            #region 加载问题的答案
            DateTime now = DateTime.Now;
            var q = from aA in db.Answer
                    where aA.QuestionID == qid
                    orderby aA.Time descending
                    select new
                    {
                        ID = aA.ID,
                        Name = aA.Teacher.Name,
                        Time = ((now.Year == aA.Time.Year) &&
                        (now.Month == aA.Time.Month) &&
                        (now.Day == aA.Time.Day)) ? string.Format("今天 {0:HH:mm}", aA.Time) : string.Format("{0:yyyy-MM-dd HH:mm}", aA.Time),
                        Memo = aA.Memo
                    };
            RecordView.DataSource = q.ToList();
            RecordView.DataBind();
            #endregion
        }

        ///
        // 初始化
        ///
        var train = (from aT in db.Train where (aT.Started - DateTime.Now).Days >= 0 orderby aT.Registed descending select aT).Take(6);
        ts = train.ToList<Train>();

        var px2 = (from aA in db.Article where aA.Verified != null orderby aA.Verified descending select aA).Take(6);
        Repeater3.DataSource = px2;
        Repeater3.DataBind();
    }
    protected string GetTopicID(string tName)
    {
        CmsDataContext db = new CmsDataContext();
        var t = from aT in db.Topic where aT.Name.Equals(tName) select aT;
        if (t.Count() != 0)
        {
            return t.First().ID;
        }
        else
        {
            return "";
        }
    }
}